package com.lzb.note.controller;

import com.lzb.note.entity.Notes;
import com.lzb.note.entity.User;
import com.lzb.note.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2021-04-29 00:51:53
 */
@RestController
@RequestMapping("user")
@Api(value = "用户类")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

//    /**
//     * 通过主键查询单条数据
//     *
//     * @param id 主键
//     * @return 单条数据
//     */
//    @GetMapping("selectOne")
//    public User selectOne(Integer id) {
//        return this.userService.queryById(id);
//    }

    @ApiOperation(value = "添加单个目标接口", notes = "")
    @PostMapping(value = "addUser",produces = "application/json;charset=UTF-8")
    public User addUser(@RequestBody User user) {
        return this.userService.insert(user);
    }
    @ApiOperation(value = "上传接口", notes = "")
    @PostMapping(value = "addAllChangeListUser",produces = "application/json;charset=UTF-8")
    public boolean addAllChangeListUser(@RequestBody List<User> notes) {
        notes.forEach(x->{
            this.userService.insert(x);
        });
        return true;
    }

    @ApiOperation(value = "删除接口", notes = "")
    @PostMapping(value = "delUser",produces = "application/json;charset=UTF-8")
    public boolean delUser(@RequestBody User user) {
        return this.userService.deleteById(user.getUserid());
    }
    @ApiOperation(value = "更新接口", notes = "")
    @PostMapping(value = "updateUser",produces = "application/json;charset=UTF-8")
    public User updateUser(@RequestBody User user) {
        return this.userService.update(user);
    }
    @ApiOperation(value = "查询接口", notes = "")
    @PostMapping(value = "selectUser",produces = "application/json;charset=UTF-8")
    public List<User> queryAll(@RequestBody User user) {
        return this.userService.queryAll(user);
    }
    @ApiOperation(value = "登录接口", notes = "")
    @PostMapping(value = "login",produces = "application/json;charset=UTF-8")
    public String login(@RequestBody User user) {
        List<User> users = this.userService.queryAll(user);
        if(CollectionUtils.isEmpty(users)){
            return "-1";
        }
        return users.get(0).getUserid();
    }

}